package com.colaps.gifts;


import java.util.ArrayList;
import java.util.List;

import com.colaps.gifts.R;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Data;
import android.view.View;
import android.widget.ListView;



public class Contacts extends Activity{
	private ListView lst;
    private List<ContactInfo> contactstock;
    private Cursor mCursor;
    
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.contactos);
		
		lst = (ListView) findViewById(android.R.id.list);
		contactstock = new ArrayList<ContactInfo>();

        mCursor = managedQuery(ContactsContract.Data.CONTENT_URI, null, Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", null,
                ContactsContract.Data.DISPLAY_NAME + " ASC");
        int number = mCursor.getColumnIndex(Phone.NUMBER);      
        int name = mCursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME);
        
        while (mCursor.moveToNext()) {
            String phName = mCursor.getString(name);
            String phNumber = mCursor.getString(number);
            contactstock.add(new ContactInfo(phName, phNumber));
        }
        
        lst.setAdapter(new ContactListAdapter(Contacts.this, contactstock));
		
	}
	
	public void pulsarMiLista(View view){
		Intent intentMiLista = new Intent(this, Gifts.class);
		startActivity(intentMiLista);	
	}
	
	@Override
	public void onBackPressed() {
       	finish();
    }
	
	@Override
	public void onStart(){
		super.onStart();
	}
	@Override
	public void onResume(){
		super.onResume();
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
	}

}
